package com.celan.year2023.month01.day06;

import java.util.PriorityQueue;
import java.util.Stack;

class MinStack {
    Stack<Integer> stack;
    PriorityQueue<Integer> queue;

    public MinStack() {
        stack = new Stack<>();
        queue = new PriorityQueue<>();
    }

    public void push(int val) {
        stack.push(val);
        queue.add(val);
    }

    public void pop() {
        int pop = stack.pop();
        queue.remove(pop);
    }

    public int top() {
        if (stack.isEmpty()) {
            return Integer.MIN_VALUE;
        }
        return stack.peek();
    }

    public int getMin() {
        if (queue.isEmpty()) {
            return Integer.MIN_VALUE;
        }
        return queue.peek();
    }
}